package com.azure.bigstore.controller;

import com.azure.bigstore.entity.Activity;
import com.azure.bigstore.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liuhuaibin on 2018/1/26.
 */
@RestController
@RequestMapping("/v1")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/activities")
    public List<Activity> getActivities(){
        return activityService.getActivities();
    }

    /**
     * get activities or an activity
     * @param id activity_id
     * @return activity_list
     */
    @GetMapping("/activities/{id}")
    public Activity getActivities(@PathVariable String id){
        return activityService.getActivity(id);
    }

    /**
     * add activity
     * @return activity
     */
    @PostMapping("/activities")
    public Activity addActivity(Activity activity){
        return activityService.saveActivity(activity);
    }

    /**
     * alter activity
     * @return activity
     */
    @RequestMapping(value = "/activities",method = RequestMethod.PUT)////////////无法解析PUT请求///////////////
    public Activity updateActivity(Activity activity){
        System.out.println("========activity:"+activity.toString());
        return activityService.saveActivity(activity) ;
    }

    /**
     * delete activity
     * @return void
     */
    @DeleteMapping("/activities/{id}")
    public void updateActivity(@PathVariable String id){
        activityService.deleteActivity(id);
    }
}
